/*   1:    */ package com.htxx.security.cipher;
/*   2:    */ 
/*   3:    */ public class DESCipher
/*   4:    */   extends BlockCipher
/*   5:    */ {
/*   6:  7 */   private int[] encryptKeys = new int[32];
/*   7:  8 */   private int[] decryptKeys = new int[32];
/*   8:  9 */   private int[] tempInts = new int[2];
/*   9: 12 */   private static byte[] bytebit = {
/*  10: 13 */     -128, 64, 32, 16, 
/*  11: 14 */     8, 4, 2, 1 };
/*  12: 18 */   private static int[] bigbyte = {
/*  13: 19 */     8388608, 4194304, 2097152, 1048576, 
/*  14: 20 */     524288, 262144, 131072, 65536, 
/*  15: 21 */     32768, 16384, 8192, 4096, 
/*  16: 22 */     2048, 1024, 512, 256, 
/*  17: 23 */     128, 64, 32, 16, 
/*  18: 24 */     8, 4, 2, 1 };
/*  19: 27 */   private static byte[] pc1 = {
/*  20: 28 */     56, 48, 40, 32, 24, 16, 8, 
/*  21: 29 */     0, 57, 49, 41, 33, 25, 17, 
/*  22: 30 */     9, 1, 58, 50, 42, 34, 26, 
/*  23: 31 */     18, 10, 2, 59, 51, 43, 35, 
/*  24: 32 */     62, 54, 46, 38, 30, 22, 14, 
/*  25: 33 */     6, 61, 53, 45, 37, 29, 21, 
/*  26: 34 */     13, 5, 60, 52, 44, 36, 28, 
/*  27: 35 */     20, 12, 4, 27, 19, 11, 3 };
/*  28: 37 */   private static int[] totrot = { 1, 2, 4, 6, 8, 10, 12, 14, 15, 17, 19, 21, 23, 25, 27, 28 };
/*  29: 39 */   private static byte[] pc2 = {
/*  30: 40 */     13, 16, 10, 23, 0, 4, 
/*  31: 41 */     2, 27, 14, 5, 20, 9, 
/*  32: 42 */     22, 18, 11, 3, 25, 7, 
/*  33: 43 */     15, 6, 26, 19, 12, 1, 
/*  34: 44 */     40, 51, 30, 36, 46, 54, 
/*  35: 45 */     29, 39, 50, 44, 32, 47, 
/*  36: 46 */     43, 48, 38, 55, 33, 52, 
/*  37: 47 */     45, 41, 49, 35, 28, 31 };
/*  38: 50 */   private static int[] SP1 = {
/*  39: 51 */     16843776, 0, 65536, 16843780, 
/*  40: 52 */     16842756, 66564, 4, 65536, 
/*  41: 53 */     1024, 16843776, 16843780, 1024, 
/*  42: 54 */     16778244, 16842756, 16777216, 4, 
/*  43: 55 */     1028, 16778240, 16778240, 66560, 
/*  44: 56 */     66560, 16842752, 16842752, 16778244, 
/*  45: 57 */     65540, 16777220, 16777220, 65540, 
/*  46: 58 */     0, 1028, 66564, 16777216, 
/*  47: 59 */     65536, 16843780, 4, 16842752, 
/*  48: 60 */     16843776, 16777216, 16777216, 1024, 
/*  49: 61 */     16842756, 65536, 66560, 16777220, 
/*  50: 62 */     1024, 4, 16778244, 66564, 
/*  51: 63 */     16843780, 65540, 16842752, 16778244, 
/*  52: 64 */     16777220, 1028, 66564, 16843776, 
/*  53: 65 */     1028, 16778240, 16778240, 
/*  54: 66 */     0, 65540, 66560, 16842756 };//016842756
/*  55: 69 */   private static int[] SP2 = {
/*  56: 70 */     -2146402272, -2147450880, 32768, 1081376, 
/*  57: 71 */     1048576, 32, -2146435040, -2147450848, 
/*  58: 72 */     -2147483616, -2146402272, -2146402304, -2147483648, 
/*  59: 73 */     -2147450880, 1048576, 32, -2146435040, 
/*  60: 74 */     1081344, 1048608, -2147450848, 
/*  61: 75 */     0, -2147483648, 32768, 1081376, -2146435072, 
/*  62: 76 */     1048608, -2147483616, 0, 1081344, 
/*  63: 77 */     32800, -2146402304, -2146435072, 32800, 
/*  64: 78 */     0, 1081376, -2146435040, 1048576, 
/*  65: 79 */     -2147450848, -2146435072, -2146402304, 32768, 
/*  66: 80 */     -2146435072, -2147450880, 32, -2146402272, 
/*  67: 81 */     1081376, 32, 32768, -2147483648, 
/*  68: 82 */     32800, -2146402304, 1048576, -2147483616, 
/*  69: 83 */     1048608, -2147450848, -2147483616, 1048608, 
/*  70: 84 */     1081344, 0, -2147450880, 32800, 
/*  71: 85 */     -2147483648, -2146435040, -2146402272, 1081344 };
/*  72: 88 */   private static int[] SP3 = {
/*  73: 89 */     520, 134349312, 0, 134348808, 
/*  74: 90 */     134218240, 0, 131592, 134218240, 
/*  75: 91 */     131080, 134217736, 134217736, 131072, 
/*  76: 92 */     134349320, 131080, 134348800, 520, 
/*  77: 93 */     134217728, 8, 134349312, 512, 
/*  78: 94 */     131584, 134348800, 134348808, 131592, 
/*  79: 95 */     134218248, 131584, 131072, 134218248, 
/*  80: 96 */     8, 134349320, 512, 134217728, 
/*  81: 97 */     134349312, 134217728, 131080, 520, 
/*  82: 98 */     131072, 134349312, 134218240, 
/*  83: 99 */     0, 512, 131080, 134349320, 134218240, 
/*  84:100 */     134217736, 512, 0, 134348808, 
/*  85:101 */     134218248, 131072, 134217728, 134349320, 
/*  86:102 */     8, 131592, 131584, 134217736, 
/*  87:103 */     134348800, 134218248, 520, 134348800, 
/*  88:104 */     131592, 8, 134348808, 131584 };
/*  89:107 */   private static int[] SP4 = {
/*  90:108 */     8396801, 8321, 8321, 128, 
/*  91:109 */     8396928, 8388737, 8388609, 8193, 
/*  92:110 */     0, 8396800, 8396800, 8396929, 
/*  93:111 */     129, 0, 8388736, 8388609, 
/*  94:112 */     1, 8192, 8388608, 8396801, 
/*  95:113 */     128, 8388608, 8193, 8320, 
/*  96:114 */     8388737, 1, 8320, 8388736, 
/*  97:115 */     8192, 8396928, 8396929, 129, 
/*  98:116 */     8388736, 8388609, 8396800, 8396929, 
/*  99:117 */     129, 0, 0, 8396800, 
/* 100:118 */     8320, 8388736, 8388737, 1, 
/* 101:119 */     8396801, 8321, 8321, 128, 
/* 102:120 */     8396929, 129, 1, 8192, 
/* 103:121 */     8388609, 8193, 8396928, 8388737, 
/* 104:122 */     8193, 8320, 8388608, 8396801, 
/* 105:123 */     128, 8388608, 8192, 8396928 };
/* 106:126 */   private static int[] SP5 = {
/* 107:127 */     256, 34078976, 34078720, 1107296512, 
/* 108:128 */     524288, 256, 1073741824, 34078720, 
/* 109:129 */     1074266368, 524288, 33554688, 1074266368, 
/* 110:130 */     1107296512, 1107820544, 524544, 1073741824, 
/* 111:131 */     33554432, 1074266112, 1074266112, 
/* 112:132 */     0, 1073742080, 1107820800, 1107820800, 33554688, 
/* 113:133 */     1107820544, 1073742080, 0, 1107296256, 
/* 114:134 */     34078976, 33554432, 1107296256, 524544, 
/* 115:135 */     524288, 1107296512, 256, 33554432, 
/* 116:136 */     1073741824, 34078720, 1107296512, 1074266368, 
/* 117:137 */     33554688, 1073741824, 1107820544, 34078976, 
/* 118:138 */     1074266368, 256, 33554432, 1107820544, 
/* 119:139 */     1107820800, 524544, 1107296256, 1107820800, 
/* 120:140 */     34078720, 0, 1074266112, 1107296256, 
/* 121:141 */     524544, 33554688, 1073742080, 524288, 
/* 122:142 */     0, 1074266112, 34078976, 1073742080 };
/* 123:145 */   private static int[] SP6 = {
/* 124:146 */     536870928, 541065216, 16384, 541081616, 
/* 125:147 */     541065216, 16, 541081616, 4194304, 
/* 126:148 */     536887296, 4210704, 4194304, 536870928, 
/* 127:149 */     4194320, 536887296, 536870912, 16400, 
/* 128:150 */     0, 4194320, 536887312, 16384, 
/* 129:151 */     4210688, 536887312, 16, 541065232, 
/* 130:152 */     541065232, 0, 4210704, 541081600, 
/* 131:153 */     16400, 4210688, 541081600, 536870912, 
/* 132:154 */     536887296, 16, 541065232, 4210688, 
/* 133:155 */     541081616, 4194304, 16400, 536870928, 
/* 134:156 */     4194304, 536887296, 536870912, 16400, 
/* 135:157 */     536870928, 541081616, 4210688, 541065216, 
/* 136:158 */     4210704, 541081600, 0, 541065232, 
/* 137:159 */     16, 16384, 541065216, 4210704, 
/* 138:160 */     16384, 4194320, 536887312, 
/* 139:161 */     0, 541081600, 536870912, 4194320, 536887312 };
/* 140:164 */   private static int[] SP7 = {
/* 141:165 */     2097152, 69206018, 67110914, 
/* 142:166 */     0, 2048, 67110914, 2099202, 69208064, 
/* 143:167 */     69208066, 2097152, 0, 67108866, 
/* 144:168 */     2, 67108864, 69206018, 2050, 
/* 145:169 */     67110912, 2099202, 2097154, 67110912, 
/* 146:170 */     67108866, 69206016, 69208064, 2097154, 
/* 147:171 */     69206016, 2048, 2050, 69208066, 
/* 148:172 */     2099200, 2, 67108864, 2099200, 
/* 149:173 */     67108864, 2099200, 2097152, 67110914, 
/* 150:174 */     67110914, 69206018, 69206018, 2, 
/* 151:175 */     2097154, 67108864, 67110912, 2097152, 
/* 152:176 */     69208064, 2050, 2099202, 69208064, 
/* 153:177 */     2050, 67108866, 69208066, 69206016, 
/* 154:178 */     2099200, 0, 2, 69208066, 
/* 155:179 */     0, 2099202, 69206016, 2048, 
/* 156:180 */     67108866, 67110912, 2048, 2097154 };
/* 157:183 */   private static int[] SP8 = {
/* 158:184 */     268439616, 4096, 262144, 268701760, 
/* 159:185 */     268435456, 268439616, 64, 268435456, 
/* 160:186 */     262208, 268697600, 268701760, 266240, 
/* 161:187 */     268701696, 266304, 4096, 64, 
/* 162:188 */     268697600, 268435520, 268439552, 4160, 
/* 163:189 */     266240, 262208, 268697664, 268701696, 
/* 164:190 */     4160, 0, 0, 268697664, 
/* 165:191 */     268435520, 268439552, 266304, 262144, 
/* 166:192 */     266304, 262144, 268701696, 4096, 
/* 167:193 */     64, 268697664, 4096, 266304, 
/* 168:194 */     268439552, 64, 268435520, 268697600, 
/* 169:195 */     268697664, 268435456, 262144, 268439616, 
/* 170:196 */     0, 268701760, 262208, 268435520, 
/* 171:197 */     268697600, 268439552, 268439616, 
/* 172:198 */     0, 268701760, 266240, 266240, 4160, 
/* 173:199 */     4160, 262208, 268435456, 268701696 };
/* 174:    */   
/* 175:    */   public DESCipher(byte[] key)
/* 176:    */   {
/* 177:204 */     super(8, 8);
/* 178:    */     
/* 179:206 */     setKey(key);
/* 180:    */   }
/* 181:    */   
/* 182:    */   public DESCipher(String keyStr)
/* 183:    */   {
/* 184:211 */     super(8, 8);
/* 185:    */     
/* 186:213 */     setKey(keyStr);
/* 187:    */   }
/* 188:    */   
/* 189:    */   private void deskey(byte[] keyBlock, boolean encrypting, int[] KnL)
/* 190:    */   {
/* 191:219 */     int[] pc1m = new int[56];
/* 192:220 */     int[] pcr = new int[56];
/* 193:221 */     int[] kn = new int[32];
/* 194:223 */     for (int j = 0; j < 56; j++)
/* 195:    */     {
/* 196:225 */       int l = pc1[j];
/* 197:226 */       int m = l & 0x7;
/* 198:227 */       pc1m[j] = ((keyBlock[(l >>> 3)] & bytebit[m]) != 0 ? 1 : 0);
/* 199:    */     }
/* 200:229 */     for (int i = 0; i < 16; i++)
/* 201:    */     {
/* 202:    */       int m;
/* 204:231 */       if (encrypting) {
/* 205:232 */         m = i << 1;
/* 206:    */       } else {
/* 207:234 */         m = 15 - i << 1;
/* 208:    */       }
/* 209:235 */       int n = m + 1;
/* 210:236 */       kn[m] = 0;
/* 211:237 */       kn[n] = 0;
/* 212:238 */       for (int j = 0; j < 28; j++)
/* 213:    */       {
/* 214:240 */         int l = j + totrot[i];
/* 215:241 */         if (l < 28) {
/* 216:242 */           pcr[j] = pc1m[l];
/* 217:    */         } else {
/* 218:244 */           pcr[j] = pc1m[(l - 28)];
/* 219:    */         }
/* 220:    */       }
/* 221:246 */       for (int j = 28; j < 56; j++)
/* 222:    */       {
/* 223:248 */         int l = j + totrot[i];
/* 224:249 */         if (l < 56) {
/* 225:250 */           pcr[j] = pc1m[l];
/* 226:    */         } else {
/* 227:252 */           pcr[j] = pc1m[(l - 28)];
/* 228:    */         }
/* 229:    */       }
/* 230:254 */       for (int j = 0; j < 24; j++)
/* 231:    */       {
/* 232:256 */         if (pcr[pc2[j]] != 0) {
/* 233:257 */           kn[m] |= bigbyte[j];
/* 234:    */         }
/* 235:258 */         if (pcr[pc2[(j + 24)]] != 0) {
/* 236:259 */           kn[n] |= bigbyte[j];
/* 237:    */         }
/* 238:    */       }
/* 239:    */     }
/* 240:262 */     cookey(kn, KnL);
/* 241:    */   }
/* 242:    */   
/* 243:    */   private void cookey(int[] raw, int[] KnL)
/* 244:    */   {
/* 245:270 */     int i = 0;int rawi = 0;
/* 246:270 */     for (int KnLi = 0; i < 16; i++)
/* 247:    */     {
/* 248:272 */       int raw0 = raw[(rawi++)];
/* 249:273 */       int raw1 = raw[(rawi++)];
/* 250:274 */       KnL[KnLi] = ((raw0 & 0xFC0000) << 6);
/* 251:275 */       KnL[KnLi] |= (raw0 & 0xFC0) << 10;
/* 252:276 */       KnL[KnLi] |= (raw1 & 0xFC0000) >>> 10;
/* 253:277 */       KnL[KnLi] |= (raw1 & 0xFC0) >>> 6;
/* 254:278 */       KnLi++;
/* 255:279 */       KnL[KnLi] = ((raw0 & 0x3F000) << 12);
/* 256:280 */       KnL[KnLi] |= (raw0 & 0x3F) << 16;
/* 257:281 */       KnL[KnLi] |= (raw1 & 0x3F000) >>> 4;
/* 258:282 */       KnL[KnLi] |= raw1 & 0x3F;
/* 259:283 */       KnLi++;
/* 260:    */     }
/* 261:    */   }
/* 262:    */   
/* 263:    */   public void setKey(byte[] key)
/* 264:    */   {
/* 265:297 */     deskey(key, true, this.encryptKeys);
/* 266:298 */     deskey(key, false, this.decryptKeys);
/* 267:    */   }
/* 268:    */   
/* 269:    */   private void des(int[] inInts, int[] outInts, int[] keys)
/* 270:    */   {
/* 271:305 */     int keysi = 0;
/* 272:    */     
/* 273:307 */     int leftt = inInts[0];
/* 274:308 */     int right = inInts[1];
/* 275:    */     
/* 276:310 */     int work = (leftt >>> 4 ^ right) & 0xF0F0F0F;
/* 277:311 */     right ^= work;
/* 278:312 */     leftt ^= work << 4;
/* 279:    */     
/* 280:314 */     work = (leftt >>> 16 ^ right) & 0xFFFF;
/* 281:315 */     right ^= work;
/* 282:316 */     leftt ^= work << 16;
/* 283:    */     
/* 284:318 */     work = (right >>> 2 ^ leftt) & 0x33333333;
/* 285:319 */     leftt ^= work;
/* 286:320 */     right ^= work << 2;
/* 287:    */     
/* 288:322 */     work = (right >>> 8 ^ leftt) & 0xFF00FF;
/* 289:323 */     leftt ^= work;
/* 290:324 */     right ^= work << 8;
/* 291:325 */     right = right << 1 | right >>> 31 & 0x1;
/* 292:    */     
/* 293:327 */     work = (leftt ^ right) & 0xAAAAAAAA;
/* 294:328 */     leftt ^= work;
/* 295:329 */     right ^= work;
/* 296:330 */     leftt = leftt << 1 | leftt >>> 31 & 0x1;
/* 297:332 */     for (int round = 0; round < 8; round++)
/* 298:    */     {
/* 299:334 */       work = right << 28 | right >>> 4;
/* 300:335 */       work ^= keys[(keysi++)];
/* 301:336 */       int fval = SP7[(work & 0x3F)];
/* 302:337 */       fval |= SP5[(work >>> 8 & 0x3F)];
/* 303:338 */       fval |= SP3[(work >>> 16 & 0x3F)];
/* 304:339 */       fval |= SP1[(work >>> 24 & 0x3F)];
/* 305:340 */       work = right ^ keys[(keysi++)];
/* 306:341 */       fval |= SP8[(work & 0x3F)];
/* 307:342 */       fval |= SP6[(work >>> 8 & 0x3F)];
/* 308:343 */       fval |= SP4[(work >>> 16 & 0x3F)];
/* 309:344 */       fval |= SP2[(work >>> 24 & 0x3F)];
/* 310:345 */       leftt ^= fval;
/* 311:346 */       work = leftt << 28 | leftt >>> 4;
/* 312:347 */       work ^= keys[(keysi++)];
/* 313:348 */       fval = SP7[(work & 0x3F)];
/* 314:349 */       fval |= SP5[(work >>> 8 & 0x3F)];
/* 315:350 */       fval |= SP3[(work >>> 16 & 0x3F)];
/* 316:351 */       fval |= SP1[(work >>> 24 & 0x3F)];
/* 317:352 */       work = leftt ^ keys[(keysi++)];
/* 318:353 */       fval |= SP8[(work & 0x3F)];
/* 319:354 */       fval |= SP6[(work >>> 8 & 0x3F)];
/* 320:355 */       fval |= SP4[(work >>> 16 & 0x3F)];
/* 321:356 */       fval |= SP2[(work >>> 24 & 0x3F)];
/* 322:357 */       right ^= fval;
/* 323:    */     }
/* 324:359 */     right = right << 31 | right >>> 1;
/* 325:360 */     work = (leftt ^ right) & 0xAAAAAAAA;
/* 326:361 */     leftt ^= work;
/* 327:362 */     right ^= work;
/* 328:363 */     leftt = leftt << 31 | leftt >>> 1;
/* 329:364 */     work = (leftt >>> 8 ^ right) & 0xFF00FF;
/* 330:365 */     right ^= work;
/* 331:366 */     leftt ^= work << 8;
/* 332:367 */     work = (leftt >>> 2 ^ right) & 0x33333333;
/* 333:368 */     right ^= work;
/* 334:369 */     leftt ^= work << 2;
/* 335:370 */     work = (right >>> 16 ^ leftt) & 0xFFFF;
/* 336:371 */     leftt ^= work;
/* 337:372 */     right ^= work << 16;
/* 338:373 */     work = (right >>> 4 ^ leftt) & 0xF0F0F0F;
/* 339:374 */     leftt ^= work;
/* 340:375 */     right ^= work << 4;
/* 341:376 */     outInts[0] = right;
/* 342:377 */     outInts[1] = leftt;
/* 343:    */   }
/* 344:    */   
/* 345:    */   public void encrypt(byte[] clearText, int clearOff, byte[] cipherText, int cipherOff)
/* 346:    */   {
/* 347:382 */     squashBytesToInts(clearText, clearOff, this.tempInts, 0, 2);
/* 348:383 */     des(this.tempInts, this.tempInts, this.encryptKeys);
/* 349:384 */     spreadIntsToBytes(this.tempInts, 0, cipherText, cipherOff, 2);
/* 350:    */   }
/* 351:    */   
/* 352:    */   public void decrypt(byte[] cipherText, int cipherOff, byte[] clearText, int clearOff)
/* 353:    */   {
/* 354:389 */     squashBytesToInts(cipherText, cipherOff, this.tempInts, 0, 2);
/* 355:390 */     des(this.tempInts, this.tempInts, this.decryptKeys);
/* 356:391 */     spreadIntsToBytes(this.tempInts, 0, clearText, clearOff, 2);
/* 357:    */   }
/* 358:    */ }


/* Location:           D:\htjs\document\wsrz\WsrzEjbInf\
 * Qualified Name:     com.htxx.security.cipher.DESCipher
 * JD-Core Version:    0.7.0.1
 */